// pages/ComeIn-centaline/book/book.js
var sayname = require("../../../template/template.js");
var WxParse = require('../../../wxParse/wxParse.js');
var menuEvent = require("../../../utils/menuEvent.js").menuEvent;
var toast = require("../../../template/Toast.js").SetToast;
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

    hqimage: app.hqimage.webUrl,
    isHide: false,
    content: '',
    menuarray: '',// [{ message: "横琴定位" }, { message: "横琴交通" }, { message: "横琴规划" }, { message: "横琴经济" }],
    menuitem: {
      showmenu1: true,
      showmenu2: true,
      showmenu3: true,
      showmenu4: true,
      showmenu5: true

    },
    userName: "",
    Sex: "",
    date: Date.now,
    Phone: "",
    remark: "",
    Sexitems: [{ name: '男' }, { name: '女' }]
  },

  binduserName: function (e) {
    var that = this;
    that.setData({
      userName: e.detail.value
    })
  },
  bindSex: function (e) {
    var that = this;
    that.setData({
      Sex: e.detail.value
    })
  },
  bindPhone: function (e) {
    var that = this;
    that.setData({
      Phone: e.detail.value
    })
  },
  bindremark: function (e) {
    var that = this;
    that.setData({
      remark: e.detail.value
    })
  },
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },

  SaveBookMsg: function (e) {
    var that = this;
    console.log(that.data.date);
    if (that.data.userName == "") {
      toast(that, "请填写姓名！")// toast组件实例
      return false;
    }
    if (that.data.Sex == "") {
      toast(that, "请选择性别！")
      return false;
    }
    if (that.data.date == "" || that.data.date == undefined) {
      toast(that, "请选择日期！")
      return false;
    }
    if (that.data.Phone == "") {
      toast(that, "请填写联系号码！")
      return false;
    }

    wx.request({
      url: app.hqApi.webUrl + "/api/C_UserAppoint/AddUserAppoint",
      data: {
        UserName: that.data.userName,
        Tel: that.data.Phone,
        Sex: that.data.Sex,
        Memo: that.data.remark,
        AtDate: that.data.date,
      /*  UserID: wx.getStorageSync('openid')*/
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: 'POST',
      success: function (res) {
        if (res.data == "OK") {

          wx.showToast({
            title: '预约成功！',
            icon: 'success',
            duration: 1000

          })
          setTimeout(function () {
            wx.redirectTo({
              url: '/pages/estate/estate'
            })
          }, 1000)

        }
        else {
          toast(that, res.data)
        }
      }
    })


  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


  /** 用户点击右上角分享
  **/
  onShareAppMessage: function () {
    return {
    title: "预约看房",
    path: "/pages/ComeIn-centaline/book/book",
   
    }
  },
  templateEvent: function (e) {
    var that = this;
    sayname.GetMemu(that, e.currentTarget.dataset.event);//加载菜单数据
    menuEvent[e.currentTarget.dataset.event](e, that);

  }
})